#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Solution {
public:
  string longestCommonPrefix(vector<string> &strs) {

    string first = strs[0];

    string result = "";
    for (int i = 0; i < first.size(); i++) {
      char ch = first[i];
      for (int j = 1; j < strs.size(); j++) {
        if (strs[j][i] != ch) {
          return result;
        }
      }
      result.push_back(ch);
    }

    return result;
  }
};
void testcase01() {
  //"flower","flow","flight"
  vector<string> input;
  input.push_back("flower");
  input.push_back("flow");
  input.push_back("flight");

  string want = "fl";
  string got;

  Solution so;
  got = so.longestCommonPrefix(input);
  if (got != want) {
    printf("failed! want:%s, but got:%s\n", want.c_str(), got.c_str());
  }
}
int main() {
  testcase01();
  return 0;
}
